<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>编辑规则</title>
	<link rel="stylesheet" href="../css/bootstrap.min.css" />
	<link rel="stylesheet" href="../css/jquery.validity.css" />
	<style type="text/css">
		body{
			background-image: url("../img/batthern.png");
		}

		.text{
			text-indent: 2em;
		}
	</style>
</head>
<body>
	<%@ include file="include/top.jsp" %>

	<div class="container" style="margin-top: 60px;">
		<div class="row">
			<jsp:include page="include/left.jsp">
				<jsp:param value="introduce" name="tag"/>
			</jsp:include>
			<div class="span9">
				<div class="wall" style="min-height: 400px;" id="right">
					    <form class="form-horizontal" method="post" action="javascript:;">
						    <fieldset>
						    <h3>投票规则</h3>
						    <div class="well">
						    <div class="control-group">
						    	<label class="control-label" for="input01" style="width: 60px;">标题</label>
							   	<div class="controls" style="margin-left: 80px;">
								    <input type="text" class="input-xlarge" id="input01" title="标题" value="<s:property value='active.title'/>"/>
							    </div>
						    </div>
						    </div>
							<textarea name="content" id="editor_id" style="width: 660px; height: 300px;">
								<s:property value="active.content" escapeHtml="false"/>
							</textarea>

							<div class="form-actions">
								<button class="btn btn-primary" id="isok">提交</button>
							</div>
						</fieldset>
					</form>
				</div>
			</div>
		</div>
		<%@ include file="include/footer.jsp" %>
	</div>

	<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	<script type="text/javascript" src="../js/welcome.js"></script>
	<script charset="utf-8" src="../editor/kindeditor.js"></script>
	<script charset="utf-8" src="../editor/lang/zh_CN.js"></script>
	<script src="../js/jquery.validity.js"></script>
	<script charset="utf-8" src="../js/jquery.validity.lang.zh.js"></script>

	<script type="text/javascript">
	    var editor;
	    KindEditor.ready(function(K) {
	            editor = K.create('textarea[name="content"]', {
				uploadJson : 'upload.jspx',
				allowImageUpload : true,
				items : [
					'undo', 'redo', '|', 'preview', 'cut', 'copy', 'paste',
			        'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
			        'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent',
			        'outdent', 'subscript','superscript', 'clearhtml', 'quickformat', 'selectall',
			        '|', 'fullscreen', '/',
			        'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'bold',
			        'italic', 'underline', 'lineheight', 'removeformat', '|', 'image',
			        'insertfile', 'table', 'hr', 'link', 'unlink'],
			});
	    }); 
	</script>
	
	<script type="text/javascript">
		$(function() {
			$.welcome($("#welcome"));
			var right = $("#right").height();
			$("#left").height(right);
			$("#right").height(right);
			
			var result;
			
			$("form").validity(function() {
				$("#input01").require().maxLength(100);
				result = $.validity.end().valid;
			});
			
			$("#isok").click(function() {
				$("form").submit();
				if(result) {
					editor.sync();
					var content = $("#editor_id").val().trim();
					if(content == "") {
						alert("内容不能为空！");
						return;
					}
					var title = $("#input01").val().trim();
					
					$.ajax({
						url : "aeditrule.jspx",
						type : "POST",
						data : {
							type : 2,
							title : title,
							content : content
						},
						success : function(msg) {
							if(msg == 1) {
								window.location.href = "showrule.jspx?type=2";
							} else if(msg == 2) {
								alert("标题和内容不能为空！");
							} else {
								alert("服务器忙，请稍后再试...");
							}
						}
					});
				}
			});
		});
	</script>
</body>
</html>


